package com.xiaochen.manager.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaochen.manager.mapper.BrandMapper;
import com.xiaochen.manager.service.BrandService;
import com.xiaochen.model.entity.product.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分类品牌(Brand)表服务实现类
 *
 * @author pinkhors
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;


    /**
     * 通过ID查询单条数据
     */
    @Override
    public Brand selectById(Long id) {
        Brand brand = brandMapper.selectById(id);
        return brand;
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo<Brand> selectByPage(Brand brand, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Brand> list = brandMapper.selectByPage(brand);
        PageInfo<Brand> brandPageInfo = new PageInfo<>(list);
        return brandPageInfo;
    }


    /**
     * 新增数据
     */
    @Override
    public void save(Brand brand) {
        brandMapper.save(brand);
    }


    /**
     * 修改数据
     */
    @Override
    public void update(Brand brand) {
        brandMapper.update(brand);
    }

    /**
     * 通过主键删除数据
     */
    @Override
    public void deleteById(Long id) {
        brandMapper.deleteById(id);
    }

    /**
     * 根据name模糊查询数据
     */
    @Override
    public List<Brand> selectByName(String name) {
        return brandMapper.selectByName(name);
    }

    @Override
    public List<Brand> findAll() {
        return brandMapper.selectByPage(null);
        // 这个位置可以直接使用selectByPage的Mapper层的方法,也可以再写一遍查询全部
        // return brandMapper.findAll();
    }
}
